package leetcode;

public class getlongestPalindrome {
    public int longestPalindrome(String s) {
        int n = s.length();
        int ret = 0;
        for(int i = 0; i < n; i++) {
            // 当回文串长度为奇数时
            int left = i - 1, right = i + 1;
            while(left >= 0 && right < n && s.charAt(left) == s.charAt(right)) {
                left--;
                right++;
            }
            ret = Math.max(ret, right - left - 1);

            // 当回文串长度为偶数时
            left = i;
            right = i + 1;
            while(left >= 0 && right < n && s.charAt(left) == s.charAt(right)) {
                left--;
                right++;
            }
            ret = Math.max(ret, right - left - 1);
        }
        return ret;
    }
}
